home *** CD-ROM | disk | FTP | other *** search
- #include <Traps.h>
-
- /* This program uses the sprintf() function to convert floating point
- ** numbers to strings.
- ** Use your favorite ANSI library (ANSI or MSL) adding the appropriate
- ** libraries to the project.
- */
-
- #include <stdio.h>
- //#include <String.h>
-
- #ifndef __FSPCOMPAT__
- #include <FSpCompat.h>
- #endif
-
-
- #include "Logger.h"
- #include "TrapAvailable.h"
-
- #define double2pstr(d,s) StrLength(s) = sprintf((char *)&s[1], "%g", (double)(d))
- #define CHARFROMMESSAGE(mess) (*(((unsigned char *)(&(mess))) + 3))
- #define ISAPPWINDOW(w) (((WindowPeek) w)->windowKind >= userKind)
- #define ISDAWINDOW(w) (((WindowPeek) w)->windowKind < 0)
-
- #define kNumber_Of_Runs 70000
-
- /* By changing the following flags you can obtain four different applications,
- ** the ones that were used to obtain the information published in the article.
- ** _PREEMPTIVERUN == 0
- ** _COOPYIELD == 0 --> cooperative thread that does not yield
- ** _COOPYIELD == 1 --> cooperative thread that yields the processor
- ** _PREEMPTIVERUN == 1
- ** _TESTBALANCE == 0 --> preemptive thread
- ** _TESTBALANCE == 1 --> preemptive thread with busy wait
- */
-
- // BEGIN configuration
- #define _PREEMPTIVERUN 0
- #define _TESTBALANCE 0
- #define _COOPYIELD 1
- // END configuration
-
-
- // BEGIN enforce correct dependencies
- #if _PREEMPTIVERUN
- #undef _COOPYIELD
- #define _COOPYIELD 0
-
- #if _TESTBALANCE
- #define HEADERSTR "\pPreemptive execution\rmaximum cooperative load\r"
- #else
- #define HEADERSTR "\pPreemptive execution\r(normal)\r"
- #endif
-
- #else
- #undef _TESTBALANCE
- #define _TESTBALANCE 0
-
- #if _COOPYIELD
- #define HEADERSTR "\pCooperative execution\r(normal)\r"
- #else
- #define HEADERSTR "\pCooperative execution\r(not yielding)\r"
- #endif
-
- #endif
- // END enforce correct dependencies
-
-
- #include "TrafficLight.h" /* bring in all the #defines for Sample */
-
-
- struct OurWindowInfoRec {
- ThreadID threadID;
- Boolean stopped;
- Boolean timeToClose;
- };
-
- typedef struct OurWindowInfoRec OurWindowInfoRec;
- typedef OurWindowInfoRec *OurWindowInfoRecPtr;
-
-
- static Rect gStopRect; /* set up by Initialize */
- static Rect gGoRect; /* set up by Initialize */
-
- /* Dhrystone stuff */
- double_t gDhrystones_Per_Second;
- Rec_Pointer Ptr_Glob, Next_Ptr_Glob;
- CursHandle gWatchHandle;
- DialogPtr gDhrystoneDialog;
- IOParam *gIOParam;
- ThreadID gDhrystoneThreadID;
- UInt32 gUser_Time = 0UL;
-
- int Int_Glob;
- int Arr_1_Glob [50];
- int Arr_2_Glob [50] [50];
- int DhrystoneCount = 0;
-
- char Ch_1_Glob, Ch_2_Glob;
- Boolean gDhrystoneDone = false;
- Boolean gInBackground = false; /* maintained by Initialize and DoEvent */
- Boolean gQuit = false;
- Boolean gThreads = false;
- Boolean Bool_Glob;
-
-
- static void Proc_1(Rec_Pointer Ptr_Val_Par);
- static void Proc_2(One_Fifty *Int_Par_Ref);
- static void Proc_3(Rec_Pointer *Ptr_Ref_Par);
- static void Proc_4(void);
- static void Proc_5(void);
- static void Proc_6(Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par);
- static void Proc_7(One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref);
- static void Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val);
- static Enumeration Func_1(Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
- static Boolean Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref);
- static Boolean Func_3(Enumeration Enum_Par_Val);
- static pascal void * DhrystoneThread(void *threadParam);
- static void Dhrystone(void);
-
-
- static void EventLoop( void );
- static void DoEvent( EventRecord *event );
- static void DoUpdate( WindowPtr window );
- static void DoActivate( WindowPtr window, Boolean becomingActive );
- static void DoContentClick( WindowPtr window );
- static void DrawWindow( WindowPtr window );
- static void AdjustMenus( void );
- static void DoMenuCommand( long menuResult );
- static void SetLight( WindowPtr window, Boolean newStopped );
- static void DoCloseWindow( WindowPtr window );
- static void DoNewWindow(void);
- static pascal void * WindowThread(void *myWindow);
- static void Terminate( void );
- static void Initialize( void );
- static void GestaltCheck(void);
- static Boolean GoGetRect( short rectID, Rect *theRect );
- static void ForceEnvirons( void );
- static void AlertUser( void );
- static void AlertUserContinue(short error);
-
-
- //extern void _DataInit();
-
-
- void main(void)
- {
- MaxApplZone(); /* expand the heap so code segments load at the top */
-
- Initialize(); /* initialize the program */
- UnloadSeg(Initialize);
-
- EventLoop(); /* call the main event loop */
- }
-
-
- void EventLoop(void)
- {
- EventRecord event;
-
- do {
- if ( WaitNextEvent(everyEvent, &event, 0UL, nil) ) {
- DoEvent(&event);
- #if _TESTBALANCE
- /* busy wait for preemptive thread */
- while (gDhrystoneDone == false) ;
- #endif
- }
- else {
- (void) YieldToThread(gDhrystoneThreadID);
- if (gDhrystoneDone)
- {
- Str255 run;
- Str255 result;
- GrafPtr savePort;
- Handle item;
- Rect rect;
- short typ;
-
- NumToString(gUser_Time, run);
- run[StrLength(run) + 1] = '\t';
-
- double2pstr(gDhrystones_Per_Second, result);
-
- result[StrLength(result) + 1] = '\r';
- if (gIOParam) {
- WriteToLogFile(gIOParam, &run[1], StrLength(run) + 1);
- WriteToLogFile(gIOParam, &result[1], StrLength(result) + 1);
- }
-
- ++DhrystoneCount;
- NumToString(DhrystoneCount, run);
- ParamText(run, result, nil, nil);
-
- /* first time only */
- if (DhrystoneCount == 1) {
- GetIndString(run, kDhrystoneString, 1);
- GetDialogItem(gDhrystoneDialog, kMessageItem, &typ, &item, &rect);
- SetDialogItemText(item, run);
- }
- /* feedback, display timings */
- GetPort(&savePort);
- SetPort(gDhrystoneDialog);
- InvalRect(&rect);
- SetPort(savePort);
- /* restart thread */
- gDhrystoneDone = false;
- (void) SetThreadState(gDhrystoneThreadID, kReadyThreadState, kNoThreadID);
- }
- }
- }
- while ( gQuit == false );
- } /*EventLoop*/
-
-
-
- void DoEvent(EventRecord *event)
- {
- Point aPoint = { kDILeft, kDITop };
- DialogPtr dummydialogptr;
- WindowPtr window;
- short part, dummyitem;
-
- if ( event->what != keyDown && event->what != autoKey && IsDialogEvent(event) )
- (void)DialogSelect(event, &dummydialogptr, &dummyitem);
- else
- switch ( event->what ) {
- case mouseDown:
- part = FindWindow(event->where, &window);
- switch ( part ) {
- case inMenuBar: /* process a mouse menu command (if any) */
- AdjustMenus();
- DoMenuCommand(MenuSelect(event->where));
- break;
- case inSysWindow: /* let the system handle the mouseDown */
- SystemClick(event, window);
- break;
- case inContent:
- if ( window != FrontWindow() ) {
- SelectWindow(window);
- /*DoEvent(event);*/ /* use this line for "do first click" */
- } else
- DoContentClick(window);
- break;
- case inDrag: /* pass screenBits.bounds to get all gDevices */
- DragWindow(window, event->where, &qd.screenBits.bounds);
- break;
- case inGrow:
- break;
- case inGoAway:
- DoCloseWindow(window);
- break;
- case inZoomIn:
- case inZoomOut:
- if ( TrackBox(window, event->where, part) ) {
- SetPort(window); /* the window must be the current port... */
- EraseRect(&window->portRect); /* because of a bug in ZoomWindow */
- ZoomWindow(window, part, true); /* note that we invalidate and erase... */
- InvalRect(&window->portRect); /* to make things look better on-screen */
- }
- break;
- }
- break;
- case keyDown:
- case autoKey: /* check for menukey equivalents */
- if ( event->modifiers & cmdKey ) /* Command key down */
- if ( event->what == keyDown ) {
- AdjustMenus(); /* enable/disable/check menu items properly */
- DoMenuCommand(MenuKey(CHARFROMMESSAGE(event->message)));
- }
- break;
- case activateEvt:
- DoActivate((WindowPtr) event->message, (event->modifiers & activeFlag) != 0);
- break;
- case updateEvt:
- DoUpdate((WindowPtr) event->message);
- break;
- case diskEvt:
- if ( HiWord(event->message) ) {
- DILoad();
- (void) DIBadMount(aPoint, event->message);
- DIUnload();
- }
- break;
- case osEvt:
- if ((*(Byte *)&event->message) == suspendResumeMessage) { /* high byte of message */
- gInBackground = (CHARFROMMESSAGE(event->message) & resumeFlag) == 0;
- DoActivate(FrontWindow(), !gInBackground);
- }
- break;
- }
- } /*DoEvent*/
-
-
- void DoUpdate(WindowPtr window)
- {
- if ( ISAPPWINDOW(window) ) {
- BeginUpdate(window); /* this sets up the visRgn */
- if ( ! EmptyRgn(window->visRgn) ) /* draw if updating needs to be done */
- DrawWindow(window);
- EndUpdate(window);
- }
- } /*DoUpdate*/
-
-
-
- void DoActivate(WindowPtr window, Boolean becomingActive)
- {
- if ( ISAPPWINDOW(window) ) {
- if ( becomingActive )
- /* do whatever you need to at activation */ ;
- else
- /* do whatever you need to at deactivation */ ;
- }
- } /*DoActivate*/
-
-
-
- void DoContentClick(WindowPtr window)
- {
- SetLight(window, ! ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->stopped);
- } /*DoContentClick*/
-
-
-
- void DrawWindow(WindowPtr window)
- {
- SetPort(window);
-
- EraseRect(&window->portRect); /* clear out any garbage that may linger */
- /* draw a red (or white) stop light */
- ForeColor( ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->stopped ? redColor : whiteColor);
- PaintOval(&gStopRect);
- ForeColor(blackColor);
- FrameOval(&gStopRect);
- /* draw a green (or white) go light */
- ForeColor( ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->stopped ? whiteColor : greenColor);
- PaintOval(&gGoRect);
- ForeColor(blackColor);
- FrameOval(&gGoRect);
- } /*DrawWindow*/
-
-
-
- void AdjustMenus(void)
- {
- WindowPtr window;
- MenuHandle menu;
-
- window = FrontWindow();
-
- menu = GetMenuHandle(mFile);
- EnableItem(menu, iNew);
- if (window)
- EnableItem(menu, iClose);
-
- menu = GetMenuHandle(mEdit);
- if (window)
- if ( ISDAWINDOW(window) ) { /* a desk accessory might need the edit menu… */
- EnableItem(menu, iUndo);
- EnableItem(menu, iCut);
- EnableItem(menu, iCopy);
- EnableItem(menu, iClear);
- EnableItem(menu, iPaste);
- } else { /* …but we don’t use it */
- DisableItem(menu, iUndo);
- DisableItem(menu, iCut);
- DisableItem(menu, iCopy);
- DisableItem(menu, iClear);
- DisableItem(menu, iPaste);
- }
-
- } /*AdjustMenus*/
-
-
-
- void DoMenuCommand(long menuResult)
- {
- Str255 daName;
- short menuID; /* the resource ID of the selected menu */
- short menuItem; /* the item number of the selected menu */
- short itemHit;
- short daRefNum;
- Boolean handledByDA;
-
- menuID = HiWord(menuResult); /* use macros for efficiency to... */
- menuItem = LoWord(menuResult); /* get menu item number and menu number */
- switch ( menuID ) {
- case mApple:
- switch ( menuItem ) {
- case iAbout: /* bring up alert for About */
- itemHit = Alert(rAboutAlert, nil);
- break;
- default: /* all non-About items in this menu are DAs */
- /* type Str255 is an array in MPW 3 */
- GetMenuItemText(GetMenuHandle(mApple), menuItem, daName);
- daRefNum = OpenDeskAcc(daName);
- break;
- }
- break;
- case mFile:
- switch ( menuItem ) {
- case iNew:
- DoNewWindow();
- break;
- case iClose:
- DoCloseWindow(FrontWindow());
- break;
- case iQuit:
- Terminate();
- break;
- }
- break;
- case mEdit: /* call SystemEdit for DA editing & MultiFinder */
- handledByDA = SystemEdit(menuItem - 1); /* since we don’t do any Editing */
- break;
- case mLight:
- switch ( menuItem ) {
- case iStop:
- SetLight(FrontWindow(), true);
- break;
- case iGo:
- SetLight(FrontWindow(), false);
- break;
- }
- break;
- }
- HiliteMenu(0); /* unhighlight what MenuSelect (or MenuKey) hilited */
- } /*DoMenuCommand*/
-
- /* Change the setting of the light. */
-
-
- void SetLight(WindowPtr window, Boolean newStopped )
- {
- if ( newStopped != ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->stopped ) {
- ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->stopped = newStopped;
- SetPort(window);
- InvalRect(&window->portRect);
- }
- } /*SetLight*/
-
-
- void
- DoNewWindow(void)
- {
- WindowPtr window;
- OurWindowInfoRecPtr windowInfoPtr;
- ThreadID theNewThread;
-
- if ( windowInfoPtr = (OurWindowInfoRecPtr) NewPtrClear(sizeof(OurWindowInfoRec))) // get refCon storage
- {
- windowInfoPtr->threadID = kNoThreadID; // init the thread ID
-
- if (window = GetNewWindow(rWindow, nil, (WindowPtr) -1)) // get the window
- {
- SetWRefCon(window, (long)windowInfoPtr); // assign it to the window
-
- if (NewThread(kCooperativeThread, (ThreadEntryProcPtr)WindowThread, (void *) window, 0, (kUsePremadeThread), nil, &theNewThread))
- {
- DisposeWindow(window);
- DisposePtr((Ptr)windowInfoPtr);
- AlertUserContinue(eCommandFailed);
- }
- else
- windowInfoPtr->threadID = theNewThread; // assign real thread ID
- }
- else {
- DisposePtr((Ptr)windowInfoPtr);
- AlertUserContinue(eCommandFailed);
- }
- }
- else
- AlertUserContinue(eCommandFailed);
- }
-
- void
- DoCloseWindow(WindowPtr window)
- {
- if (window)
- if ( ISDAWINDOW(window) )
- CloseDeskAcc(((WindowPeek) window)->windowKind);
- else if ( ISAPPWINDOW(window) )
- ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->timeToClose = true;
- } /*DoCloseWindow*/
-
-
- pascal void *
- WindowThread(void *myWindow)
- {
- WindowPtr window;
- unsigned long baseTicks, currTicks;
- Boolean toggle;
- OurWindowInfoRecPtr windowInfoPtr;
-
- window = (WindowPtr) myWindow; // get the window
- windowInfoPtr = (OurWindowInfoRecPtr) (((WindowPeek) window)->refCon); // get the data (inited by DoNewWindow)
-
- baseTicks = TickCount();
- toggle = false;
- for (;;)
- {
- if (windowInfoPtr->timeToClose)
- {
- DisposeWindow(window);
- window = nil;
- (void) DisposeThread(kCurrentThreadID, 0, true); // and the lights go out...
- }
-
- currTicks = TickCount();
- if (baseTicks + 60 <= currTicks)
- {
- SetLight(window, toggle);
- toggle = ! toggle;
- baseTicks = currTicks;
- }
-
- (void) YieldToThread(gDhrystoneThreadID);
- }
-
- return((void *) 'Wind');
- }
-
-
- void Terminate(void)
- {
- WindowPtr aWindow;
- OSErr myErr;
- char ret = '\r';
-
- while ((aWindow = FrontWindow()) != nil)
- {
- if (((WindowPeek) aWindow)->windowKind == dialogKind)
- CloseDialog((DialogPtr) aWindow);
- else
- {
- DoCloseWindow(aWindow);
- myErr = YieldToThread(((OurWindowInfoRecPtr) (((WindowPeek) aWindow)->refCon))->threadID);
- if (myErr)
- DebugStr ("\p Error from YieldToThread in Terminate()");
- }
- }
- if (gIOParam) {
- WriteToLogFile(gIOParam, &ret, 1);
- CloseLogFile(gIOParam);
- }
- gQuit = true;
- } /*Terminate*/
-
- #pragma segment Init
-
- void Initialize(void)
- {
- Str255 s = HEADERSTR;
- FSSpec fSpec;
- Handle menuBar;
- EventRecord event;
- int count;
- OSErr err;
- Boolean exists;
-
- MoreMasters();
- MoreMasters();
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- FlushEvents(everyEvent, 0);
- InitCursor();
-
- (void)UnloadScrap();
- (void)TEFromScrap();
-
- GestaltCheck(); /* check for environment */
-
- gWatchHandle = GetCursor(watchCursor);
- SetCursor(*gWatchHandle);
-
- for (count = 1; count <= 3; count++)
- EventAvail(everyEvent, &event);
-
- (void) CreateThreadPool(kCooperativeThread, 6, 0);
- #if _PREEMPTIVERUN
- (void) CreateThreadPool(kPreemptiveThread, 1, 0);
- #endif
-
- menuBar = GetNewMBar(rMenuBar); /* read menus into menu bar */
- if ( menuBar == nil )
- AlertUser();
- SetMenuBar(menuBar); /* install menus */
- DisposeHandle(menuBar);
- AppendResMenu(GetMenuHandle(mApple), 'DRVR'); /* add DA names to Apple menu */
- DrawMenuBar();
-
- if ( !GoGetRect(rStopRect, &gStopRect) )
- AlertUser(); /* the stop light rectangle */
- if ( !GoGetRect(rGoRect, &gGoRect) )
- AlertUser(); /* the go light rectangle */
-
- gDhrystoneDialog = GetNewDialog(kDhrystoneDLOG, nil, (WindowPtr)-1);
-
- err = FSMakeFSSpecCompat(-1, 0, "\pthreadlog", &fSpec);
- if (err == fnfErr)
- exists = false;
- else if (err == noErr)
- exists = true;
- else
- AlertUser();
- gIOParam = OpenLogFile(&fSpec, 'CWIE', &err, exists);
- if (gIOParam) {
- WriteToLogFile(gIOParam, &s[1], StrLength(s));
- }
-
- if (NewThread(
- #if _PREEMPTIVERUN
- kPreemptiveThread
- #else
- kCooperativeThread
- #endif
- , (ThreadEntryProcPtr)DhrystoneThread, (void *) 0, 0, (kUsePremadeThread), nil, &gDhrystoneThreadID))
- AlertUser();
-
- InitCursor();
- } /*Initialize*/
-
- /* GestaltCheck: is this Mac set up with all we need to run? */
-
- static void GestaltCheck(void)
- {
- enum {
- // preemptive scheduler fix present?
- gestaltSchedulerFix = 3
- };
-
- enum {
- kMinimumMemoryFree = 64L*1024
- };
-
- #define POWERMANAGER ((1L << gestaltPMgrExists)|(1L << gestaltPMgrCPUIdle))
- #define TEMPMEMMANAGER ((1L << gestaltTempMemSupport)|(1L << gestaltRealTempMemory)|(1L << gestaltTempMemTracked))
- long Gresp;
- unsigned long totalSize, contigSize;
-
- PurgeSpace((long *)&totalSize, (long *)&contigSize);
- if (totalSize < kMinimumMemoryFree) {
- AlertUser();
- }
- if (TrapAvailable(_Gestalt)) {
- if (Gestalt(gestaltThreadMgrAttr, &Gresp) == noErr) {
- gThreads = (Gresp & (1L << gestaltThreadMgrPresent)) &&
- (Gresp & (1L << gestaltSchedulerFix));
- }
- }
- #if GENERATINGCFM
- if (gThreads)
- if (NewThread == (void *)kUnresolvedCFragSymbolAddress)
- gThreads = false;
- #endif
- if (gThreads == false)
- AlertUser();
- }
-
-
- Boolean GoGetRect(short rectID, Rect *theRect)
- {
- Handle resource;
-
- resource = Get1Resource('RECT', rectID);
- return resource ? (*theRect = *(RectPtr)*resource, true) : false;
- } /* GoGetRect */
-
- #pragma segment Main
-
- /* -----------------------------------------------------------------------------
- *
- * Dhrystone.
- *
- * -----------------------------------------------------------------------------*/
-
- pascal void *
- DhrystoneThread(void *threadParam)
- {
- #pragma unused (threadParam)
-
- UInt32 User_Time;
-
-
- for (;;) {
- User_Time = LMGetTicks();
-
- Dhrystone();
-
- User_Time = LMGetTicks() - User_Time;
- gDhrystones_Per_Second = (double_t)(60 * kNumber_Of_Runs) / (double_t) User_Time;
- gUser_Time = User_Time;
-
- (void) ThreadBeginCritical();
- gDhrystoneDone = true;
- (void) SetThreadStateEndCritical(kCurrentThreadID, kStoppedThreadState, kNoThreadID);
- }
-
- return((void *) 'Dhry');
- }
-
- void
- Dhrystone(void)
- {
- One_Fifty Int_1_Loc;
- register One_Fifty Int_2_Loc;
- One_Fifty Int_3_Loc;
- register char Ch_Index;
- Enumeration Enum_Loc;
- Str_30 Str_1_Loc;
- Str_30 Str_2_Loc;
- register UInt32 Run_Index;
- Rec_Type fake_malloc1;
- Rec_Type fake_malloc2;
-
-
- #if _COOPYIELD
- UInt32 base_Time = LMGetTicks();
- UInt32 curr_Time;
- #endif
-
- /* Initializations */
-
- Next_Ptr_Glob = (Rec_Pointer) &fake_malloc1;
- Ptr_Glob = (Rec_Pointer) &fake_malloc2;
-
- Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
- Ptr_Glob->Discr = Ident_1;
- Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
- Ptr_Glob->variant.var_1.Int_Comp = 40;
- strcpy (Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING");
- strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
-
- /* Was missing in published program. Without this statement, */
- /* Arr_2_Glob [8][7] would have an undefined value. */
- /* Warning: With 16-Bit processors and kNumber_Of_Runs > 32000, */
- /* overflow may occur for this array element. */
- Arr_2_Glob [8][7] = 10;
-
- for (Run_Index = 1; Run_Index <= kNumber_Of_Runs; ++Run_Index) {
- // if((Run_Index & 0xFFF) == 0) YieldToAnyThread();
-
- Proc_5();
- Proc_4();
-
- /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
- Int_1_Loc = 2;
- Int_2_Loc = 3;
- strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
- Enum_Loc = Ident_2;
- Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
- /* Bool_Glob == 1 */
-
- while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
- {
- Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
- /* Int_3_Loc == 7 */
- Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
- /* Int_3_Loc == 7 */
- Int_1_Loc += 1;
- } /* while */
-
- /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
- Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
-
- /* Int_Glob == 5 */
- Proc_1 (Ptr_Glob);
- for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index) /* loop executed twice */
- {
- if (Enum_Loc == Func_1 (Ch_Index, 'C')) /* then, not executed */
- {
- Proc_6 (Ident_1, &Enum_Loc);
- strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
- Int_2_Loc = Run_Index;
- Int_Glob = Run_Index;
- }
- }
-
- /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
- Int_2_Loc = Int_2_Loc * Int_1_Loc;
- Int_1_Loc = Int_2_Loc / Int_3_Loc;
- Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
-
- /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
- Proc_2 (&Int_1_Loc);
-
- /* Int_1_Loc == 5 */
-
- #if _COOPYIELD
- curr_Time = LMGetTicks();
- if (curr_Time > base_Time + 10UL) {
- YieldToAnyThread();
- base_Time = curr_Time;
- }
- #endif
-
- } /* loop "for Run_Index" */
- }
-
- /* executed once */
- void
- Proc_1(/*register*/ Rec_Pointer Ptr_Val_Par)
- {
- register Rec_Pointer Next_Record;
-
- Next_Record = Ptr_Val_Par->Ptr_Comp; /* == Ptr_Glob_Next */
-
- /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
- /* corresponds to "rename" in Ada, "with" in Pascal */
-
- *Ptr_Val_Par->Ptr_Comp = *Ptr_Glob;
- Ptr_Val_Par->variant.var_1.Int_Comp = 5;
- Next_Record->variant.var_1.Int_Comp = Ptr_Val_Par->variant.var_1.Int_Comp;
- Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
- Proc_3 (&Next_Record->Ptr_Comp);
- /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp == Ptr_Glob->Ptr_Comp */
-
- if (Next_Record->Discr == Ident_1) /* then, executed */
- {
- Next_Record->variant.var_1.Int_Comp = 6;
- Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, &Next_Record->variant.var_1.Enum_Comp);
- Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
- Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, &Next_Record->variant.var_1.Int_Comp);
- }
- else /* not executed */
- *Ptr_Val_Par = *Ptr_Val_Par->Ptr_Comp;
- } /* Proc_1 */
-
-
- /* executed once */
- /* *Int_Par_Ref == 1, becomes 4 */
- void
- Proc_2(One_Fifty *Int_Par_Ref)
- {
- One_Fifty Int_Loc;
- Enumeration Enum_Loc;
-
- Int_Loc = *Int_Par_Ref + 10;
- do /* executed once */
- if (Ch_1_Glob == 'A') /* then, executed */
- {
- Int_Loc -= 1;
- *Int_Par_Ref = Int_Loc - Int_Glob;
- Enum_Loc = Ident_1;
- } /* if */
-
- while (Enum_Loc != Ident_1); /* true */
- } /* Proc_2 */
-
-
- /* executed once */
- /* Ptr_Ref_Par becomes Ptr_Glob */
- void
- Proc_3(Rec_Pointer *Ptr_Ref_Par)
- {
- if (Ptr_Glob != nil) /* then, executed */
- *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
- Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
- } /* Proc_3 */
-
-
- /* executed once */
- void
- Proc_4(void)
- {
- Boolean Bool_Loc;
-
- Bool_Loc = Ch_1_Glob == 'A';
- Bool_Glob = Bool_Loc | Bool_Glob;
- Ch_2_Glob = 'B';
- } /* Proc_4 */
-
-
- /* executed once */
- void
- Proc_5(void)
- {
- Ch_1_Glob = 'A';
- Bool_Glob = false;
- } /* Proc_5 */
-
- /* executed once */
- /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
- void
- Proc_6(Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par)
- {
- *Enum_Ref_Par = Enum_Val_Par;
- if (! Func_3 (Enum_Val_Par)) /* then, not executed */
- *Enum_Ref_Par = Ident_4;
- switch (Enum_Val_Par)
- {
- case Ident_1:
- *Enum_Ref_Par = Ident_1;
- break;
- case Ident_2:
- if (Int_Glob > 100)
- *Enum_Ref_Par = Ident_1;
- else
- *Enum_Ref_Par = Ident_4;
- break;
- case Ident_3: /* executed */
- *Enum_Ref_Par = Ident_2;
- break;
- case Ident_4: break;
- case Ident_5:
- *Enum_Ref_Par = Ident_3;
- break;
- } /* switch */
- } /* Proc_6 */
-
-
- /* executed three times */
- /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
- /* Int_Par_Ref becomes 7 */
- /* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
- /* Int_Par_Ref becomes 17 */
- /* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
- /* Int_Par_Ref becomes 18 */
- void
- Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref)
- {
- One_Fifty Int_Loc;
-
- Int_Loc = Int_1_Par_Val + 2;
- *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
- } /* Proc_7 */
-
-
- /* executed once */
- /* Int_Par_Val_1 == 3 */
- /* Int_Par_Val_2 == 7 */
- void
- Proc_8 (Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val)
- {
- register One_Fifty Int_Index;
- register One_Fifty Int_Loc;
-
- Int_Loc = Int_1_Par_Val + 5;
- Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
- Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
- Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
- for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
- Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
- Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
- Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
- Int_Glob = 5;
- } /* Proc_8 */
-
-
- /* executed three times */
- /* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */
- /* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */
- /* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */
- Enumeration
- Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val)
- {
- Capital_Letter Ch_1_Loc;
- Capital_Letter Ch_2_Loc;
-
- Ch_1_Loc = Ch_1_Par_Val;
- Ch_2_Loc = Ch_1_Loc;
- if (Ch_2_Loc != Ch_2_Par_Val) /* then, executed */
- return (Ident_1);
- else /* not executed */
- {
- Ch_1_Glob = Ch_1_Loc;
- return (Ident_2);
- }
- } /* Func_1 */
-
-
- /* executed once */
- /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
- /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
- Boolean
- Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref)
- {
- register One_Thirty Int_Loc;
- Capital_Letter Ch_Loc;
-
- Int_Loc = 2;
- while (Int_Loc <= 2) /* loop body executed once */
- {
- if (Func_1 (Str_1_Par_Ref[Int_Loc], Str_2_Par_Ref[Int_Loc+1]) == Ident_1) /* then, executed */
- {
- Ch_Loc = 'A';
- Int_Loc += 1;
- }
- }
-
- if (Ch_Loc >= 'W' && Ch_Loc < 'Z') /* then, not executed */
- Int_Loc = 7;
-
- if (Ch_Loc == 'R') /* then, not executed */
- return (true);
- else /* executed */
- {
- if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
- /* then, not executed */
- {
- Int_Loc += 7;
- Int_Glob = Int_Loc;
- return (true);
- }
- else /* executed */
- return (false);
- } /* if Ch_Loc */
- } /* Func_2 */
-
-
- /* Func_3. Whether Enum_Par_Val == Ident_3 */
- Boolean
- Func_3 (Enumeration Enum_Par_Val)
- {
- Enumeration Enum_Loc;
-
- Enum_Loc = Enum_Par_Val;
- return (Enum_Loc == Ident_3);
- } /* Func_3 */
-
- /* -----------------------------------------------------------------------------
- *
- * Utility routines.
- *
- * -----------------------------------------------------------------------------*/
-
- void
- AlertUserContinue(short /*error*/)
- {
- //Str255 message;
-
- SetCursor(&qd.arrow);
- //GetIndString(message, kErrStrings, error);
- //ParamText(message, "\p", nil, nil);
- (void) StopAlert(130, nil);
- }
-
- #pragma segment Init
-
- void AlertUser(void)
- {
- SetCursor(&qd.arrow);
- (void) StopAlert(rUserAlert, nil);
- ExitToShell();
- } /* AlertUser */
-
-